﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ExecucaoGravacao
{
    public partial class SelecionaOrdem : Form
    {
        public SelecionaOrdem()
        {
            InitializeComponent();
        }

        public List<string> files = new List<string>();

        private void button1_Click(object sender, EventArgs e)
        {
            if(lstItens.SelectedItem != null)
            {
                object obj = lstItens.SelectedItem;
                int index = lstItens.SelectedIndex;

                if(index != 0)
                {
                    files.RemoveAt(index);

                    if(index - 1 >= 0)
                    {
                        files.Insert(index - 1, (string)obj);
                        lstItens.DataSource = null;
                        lstItens.DataSource = files;
                        lstItens.SelectedIndex = index - 1;
                    }
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(lstItens.SelectedItem != null)
            {
                object obj = lstItens.SelectedItem;
                int index = lstItens.SelectedIndex;


                if(index != lstItens.Items.Count - 1)
                {

                    files.RemoveAt(index);

                    if(index + 1 <= lstItens.Items.Count - 1)
                    {
                        files.Insert(index + 1, (string)obj);
                        lstItens.DataSource = null;
                        lstItens.DataSource = files;
                        lstItens.SelectedIndex = index + 1;

                    }
                }
            }
        }

        private void SelecionaOrdem_Load(object sender, EventArgs e)
        {
            lstItens.DataSource = files;
        }

        private void btnFechar_Click(object sender, EventArgs e)
        {
            ((ExecucaoGravacao)Owner).files = (List<string>)lstItens.DataSource;
            this.Close();
        }
    }
}
